import 'package:flustars_flutter3/flustars_flutter3.dart';
import 'package:flutter/material.dart';
import 'package:ls_work/a_message/models/message_section_entity.dart';
import 'package:ls_work/res/styles.dart';
import 'package:ls_work/util/image_utils.dart';

class MessageSectionView extends StatelessWidget {
  final MessageSectionInfo? info;
  MessageSectionView({Key? key, this.info});
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.fromLTRB(0, 12, 12, 12),
      width: ScreenUtil.getScreenW(context),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.start,
        children: <Widget>[
          Stack(
            children: [
              Container(
                height: 50,
                padding: EdgeInsets.only(left: 12),
                alignment: Alignment.center,
                child: CircleAvatar(
                  backgroundImage:
                      ImageUtils.getImageProvider('${info?.avatar}'),
                ),
              ),
              (info?.unreadCount??0) > 0
                  ? Positioned(
                      right: 0,
                      top: 0,
                      child: Container(
                        padding: EdgeInsets.all(5),
                        decoration: BoxDecoration(
                          color: Colors.red,
                          shape: BoxShape.circle,
                        ),
                        child: Text(
                          (info?.unreadCount??0) > 99 ? "99+" : '${info?.unreadCount??0}',
                          style: TextStyle(color: Colors.white, fontSize: 12),
                        ),
                      ),
                    )
                  : SizedBox()
            ],
          ),
          SizedBox(
            width: 10,
          ),
          Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Container(
                  width: ScreenUtil.getScreenW(context) - 79,
                  alignment: Alignment.centerRight,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: <Widget>[
                      Expanded(
                        child: Text('${info?.name??""}',
                            style: TextStyles.textDark16,
                            maxLines: 1,
                            overflow: TextOverflow.ellipsis),
                      ),
                      SizedBox(
                        width: 8,
                      ),
                      Text(
                        TimelineUtil.format(
                            DateUtil.getDateMsByTimeStr(info?.lastMsgTime??"")??0,
                            dayFormat: DayFormat.Common),
                        style: TextStyles.textGray12,
                      ),
                    ],
                  )),
              SizedBox(
                height: 8,
              ),
              Container(
                width: ScreenUtil.getScreenW(context) - 79,
                child: Text(
                  '${info?.lastMsg?.content??""}',
                  maxLines: 2,
                  overflow: TextOverflow.ellipsis,
                  style: TextStyles.textGray14,
                ),
              )
            ],
          )
        ],
      ),
    );
  }
}
